<template>
  <div>
    <el-form :inline="true" :model="form" class="demo-form-inline">
      <el-form-item label="查询">
        <el-input v-model="form.name" placeholder="用户名、用户操作" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="tableData"
      style="width: 100%"
      height="500"
      border
    >
      <el-table-column type="index" width="50" :show-overflow-tooltip="true" />
      <el-table-column prop="username" label="用户名" :show-overflow-tooltip="true" />
      <el-table-column prop="operation" label="用户操作" :show-overflow-tooltip="true" />
      <el-table-column prop="method" label="请求方法" :show-overflow-tooltip="true" />
      <el-table-column prop="params" label="请求参数" :show-overflow-tooltip="true" />
      <el-table-column prop="time" label="执行时长（毫秒）" :show-overflow-tooltip="true" />
      <el-table-column prop="ip" label="IP地址" />
      <el-table-column prop="createDate" label="创建时间" />
    </el-table>
    <el-pagination
      background
      :current-page="form.pageNum"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="form.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>
<script>
export default {
  name: 'SysLog',
  data() {
    return {
      tableData: [],
      form: {
        pageNum: 1,
        pageSize: 10,
        name: ''
      },
      total: 0
    }
  },
  created() {
    this.list()
  },
  methods: {
    list() {
      this.axios({
        method: 'post',
        url: 'http://localhost:9999/system-management/sysLog/list',
        data: this.form
      }).then((res) => {
        this.tableData = res.data.list
        this.form.pageNum = res.data.pageNum
        this.form.pageSize = res.data.pageSize
        this.total = res.data.total
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.form.pageSize = val
      this.list()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.form.pageNum = val
      this.list()
    },
    onSubmit() {
      console.log('submit!')
      this.list()
    }
  }
}
</script>
